<?php
class Telesched extends Controller {

	private $aPost;

	function Telesched() {

		parent::Controller();
		$this -> load -> model('model_telesched');

		//verificare sesiune
		if (!$this -> usersession -> userLoggedIn()) {
			$aResponse = array("error" => true, "description" => "Sesiunea a expirat", "type" => "nosession");
			die(json_encode($aResponse));
		}
		copyPost($this -> aPost);
		$this -> aUser = $this -> usersession -> currentUser();
	}

	/**
	 * Functie care aduce datele in grid
	 */
	function getData() {
		echo json_encode($this -> model_telesched -> getData($_POST));
	}

	/**
	 * Functie de editare / inserare element
	 * @return string json
	 */
	function operation() {

		$bResponse = $this -> model_telesched -> operation($this -> aPost);

		if ($bResponse === TRUE) {
			$aResponse = array("error" => false, "success" => true, "description" => "Datele au fost salvate");
		}
		else {
			$aResponse = array("error" => true, "description" => $bResponse, "type" => "Validare");
		}
		echo json_encode($aResponse);
	}

	/**
	 * Functie care aduce datele despre unei inregistrari
	 * @return string json
	 */
	function getRecord() {
		$aResult = $this -> model_telesched -> getRecord($this -> aPost);
		echo json_encode(array("error" => false, "data" => $aResult));
	}

	function deleteProgramare() {
		$this -> db -> where("tsched_id", $this -> aPost["tsched_id"]);
		$this -> db -> delete("tele_schedule");
		$aResponse = array("error" => false, "success" => true, "description" => "Datele au fost salvate");
		echo json_encode($aResponse);
	}

}
